package com.bs.web.rest;

import com.bs.service.ActionConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by wenguangjia on 2017/6/1.
 */
@RestController
@RequestMapping("/actionconfig/api/")
public class ActionConfigResource {
    @Autowired
    ActionConfigService actionConfigService;

    @GetMapping("/query/{location}")
    @ResponseBody
    public Map<Object, Object> query(@PathVariable String location){
        Map map = actionConfigService.query(location);
        return map;
    }
    @PostMapping("/save/{location}")
    @ResponseBody
    public Map<String, String> save(@PathVariable String location, @RequestBody Map<Object,Object> map){
        Map<String,String> result=new HashMap<>();
        try {
            actionConfigService.save(location,map);
            result.put("state","success");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            result.put("state",e.getMessage());
        }
        return result;
    }
}
